﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ArraysAndStrings.Rotate
{
    class MainProject
    {
        static void Main(string[] args)
        {
            int[][] nums = new int[][]
           {
                new int[] { 1,2,3} ,
                new int[] { 4,5,6} ,
                new int[] { 7,8,9} ,
           };
            Rotate(nums);

            foreach (var item in nums)
            {
                foreach (var item1 in item)
                {
                    Console.WriteLine(item1);
                }
            }
            Console.ReadKey();
        }
        public static void Rotate(int[][] matrix)
        {
            // x = y  y = length-1-x
            Queue<int[]> que = new Queue<int[]>();
            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    que.Enqueue(new int[] { i, j, matrix[i][j]});
                }
            }
            while (que.Count>0)
            {
                int[] array = que.Dequeue();
                matrix[array[1]][matrix.Length - 1 - array[0]] = array[2];
            }
        }
    }
}
